#include "ParticleJet.h"

#include "ParticleContext.h"
#include "DescriptorParticle.h"

#include "ParticleSimple.h"

using namespace ParticleEngine; 

const DescriptorParticle ParticleJet::Descriptor
(
	"Jet", 
	[](ParticleContext& NewContext) { return new ParticleJet(NewContext); }
); 

ParticleJet::ParticleJet(ParticleContext& NewContext) :
ParticleBase(NewContext, &ParticleJet::Descriptor),
PropertyAdhesions(0.15f),
Heat(1.0f),
Electricity(0.5f),
Counter(0)
{
	this->Adhesions = dynamic_cast<PropertyAdhesions*>(this);
	this->Adhesions->ParticleCast = dynamic_cast<ParticleBase*>(this);
}

ParticleJet::~ParticleJet()
{
}

void ParticleJet::Sole()//einzelne aktualisierzung
{
	this->SoleStandard();

	this->Heat.Sole();
	this->Electricity.Sole();

	this->Signal0.Sole();
	this->Signal1.Sole();

	Switch.Sole(this->Signal0, this->Signal1);
	if (Switch.Status == true)
		DirectionTracer.Sole(this);

	if (Switch.Status == true && Electricity.Volume > JET_ELECTRICITY_CONSUM && DirectionTracer.DirectorFound > 0)
	{
		const unsigned char SpepsToSimple = 70;
		const float Power = 0.0012f;

		this->Velocity += DirectionTracer.Direction * Power;
		this->Electricity.Volume -= JET_ELECTRICITY_CONSUM;

		Counter ++;
		if (Counter >= SpepsToSimple)
		{
			Counter = 0;
			ParticleBase *NewP;
			NewP = new ParticleSimple(Context);
			NewP->Pos = this->Pos - DirectionTracer.Direction * 1.6f;
			NewP->Velocity = this->Velocity - DirectionTracer.Direction * Power * SpepsToSimple;
			this->Context.ToAddArray.Add(NewP);
		}
	}

}
void ParticleJet::InteractionIndividual(ParticleBase*const Other, Vec<2, float>& Space, const float& DistanceSquared)
{
	this->InteractionKinetics(Other, Space, DistanceSquared);

	this->Heat.Interaction(Other->HasHeat());
	this->Electricity.Interaction(Other->HasElectricity());

	this->Signal0.Interaction(Other->HasSignal0());
	this->Signal1.Interaction(Other->HasSignal1());


}
ColorRGBA<unsigned char> ParticleJet::GetColor()
{
	return ColorRGBA<unsigned char> (0, 255, 255, 255);
}

void ParticleJet::SaveIndividual(std::ofstream& Strm)
{
	Heat.Save(Strm);
	Electricity.Save(Strm);

	Signal0.Save(Strm);
	Signal1.Save(Strm);
}
void ParticleJet::LoadIndividual(std::ifstream& Strm)
{
	Heat.Load(Strm);
	Electricity.Load(Strm);

	Signal0.Load(Strm);
	Signal1.Load(Strm);
}


